package com.cennavi.buss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.cennavi.buss.service.imp.ISoluService;
import com.cennavi.minemap.bean.MessageBean;

@RestController
@RequestMapping("/service/solu")
public class SoluController {
	@Autowired
	private ISoluService iSoluService;

	@RequestMapping(method = RequestMethod.POST, value = "/add", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean insert(@RequestBody String json) {
		return iSoluService.insert(json);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/update", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean update(@RequestBody String json) {
		return iSoluService.update(json);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/delete/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean delete(@PathVariable int id) {
		return iSoluService.delete(id);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/list/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryByUserId(@PathVariable int userId) {
		return iSoluService.queryByUserId(userId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/nameList/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryIdNameByUserId(@PathVariable int userId) {
		return iSoluService.queryIdNameByUserId(userId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/template/list", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryTemplate() {
		return iSoluService.queryTemplate();
	}

	@RequestMapping(method = RequestMethod.GET, value = "/template2/list", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryTemplate2() {
		return iSoluService.queryTemplate2ByUserId();
	}

	@RequestMapping(method = RequestMethod.GET, value = "/edit/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryById(@PathVariable int id, @RequestParam("token") String token) {
		return iSoluService.queryById(id, token);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryPublishById(@PathVariable int id, @RequestParam("token") String token) {
		return iSoluService.queryPublishById(id, token);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/url/{url}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryByUrl(@PathVariable String url, @RequestParam("token") String token) {
		return iSoluService.queryByUrl(url, token);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/publish/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean publish(@PathVariable int id) {
		return iSoluService.publish(id);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/copy/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean copy(@PathVariable(value = "id") int id, @RequestBody String json) {
		return iSoluService.copy(id, json);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/style/edit/id/{id}")
	public @ResponseBody String queryStyle(@PathVariable int id) throws Exception {
		return iSoluService.queryStyle(id);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/style/id/{id}")
	public @ResponseBody String queryPublishStyle(@PathVariable int id) {
		return iSoluService.queryPublishStyle(id);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/style/url/{url}")
	public @ResponseBody String queryStyle(@PathVariable String url) {
		return iSoluService.queryStyle(url);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/export")
	public ResponseEntity<Resource> download(@RequestParam("id") Integer id) {
		ResponseEntity<Resource> res = iSoluService.download(id);
		return res;
	}

	@RequestMapping(method = RequestMethod.POST, value = "/import")
	public Integer upload(@RequestParam("file") MultipartFile file, @RequestParam("userId") Integer userId) {
		return iSoluService.upload(file, userId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/upload/findSolu/{uploadId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean querySoluListByUploadId(@PathVariable Integer uploadId) {
		return iSoluService.querySoluListByUploadId(uploadId);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/upload/update/", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean updateUploadSolu(@RequestBody String json) {
		return iSoluService.updateUploadSolu(json);
	}
	
	@RequestMapping(value = "/thumbnail/add", method = RequestMethod.POST)
	public @ResponseBody MessageBean insertThumbnail(@RequestBody String json){
		return iSoluService.insertThumbnail(json);
	}
	
	@RequestMapping(value = "/thumbnail/update", method = RequestMethod.POST)
	public @ResponseBody MessageBean updateThumbnail(@RequestBody String json){
		return iSoluService.updateThumbnail(json);
	}

	@RequestMapping(value = "/thumbnail/delete/{soluId}")
	public @ResponseBody MessageBean deleteThumbnail(@PathVariable int soluId) {
		return iSoluService.deleteThumbnail(soluId);
	}
	
	@RequestMapping(value = "/thumbnail/find/{soluId}")
	public @ResponseBody MessageBean queryThumbnailBySoluId(@PathVariable int soluId) {
		return iSoluService.queryThumbnailBySoluId(soluId);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/withPrefixLayer/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryWithPrefixLayerById(@PathVariable int id, @RequestParam("token") String token) {
		return iSoluService.queryWithPrefixLayerById(id, token);
	}
}
